﻿using System;
using System.IO;
using UnityEngine;

/// <summary>
/// 资源类型
/// </summary>
public enum AssetType
{
    Texure,Model,Scene,Text,Video,Other
}
public class AssetManager : MonoBehaviour
{

    private static string _cacheDir = "";

    public static AssetManager _instance;
    public static AssetManager Instance
    {
        get
        {
            if (_instance == null)
            {
                GameObject go = new GameObject("_AssetManager");
                _instance = go.AddComponent<AssetManager>();
            }
            return _instance;
        }
    }
    public static string CacheDir
    {
        get
        {
            return _cacheDir;
        }
    }


    /// <summary>
    /// 将字节转换为直观大小
    /// </summary>
    /// <param name="bytes">字节数</param>
    /// <returns></returns>
    public static string FormatBytes(int bytes)
    {
        string[] Suffix = { "Byte", "KB", "MB", "GB", "TB" };
        int i = 0;
        double dblSByte = bytes;
        if (bytes > 1024)
            for (i = 0; (bytes / 1024) > 0; i++, bytes /= 1024)
                dblSByte = bytes / 1024.0;
        return string.Format("{0:0.##}{1}", dblSByte, Suffix[i]);
    }

    

    public void Init(string cacheDirName = "EduCache")
    {
        if (Application.platform == RuntimePlatform.Android)
        {
            _cacheDir = "sdcard/LetinSaaS/" + cacheDirName + "";
            
        }
        else
        {
            _cacheDir = new DirectoryInfo(Application.dataPath).Parent.FullName + @"\" + cacheDirName;
            if (!Directory.Exists(_cacheDir))
            {
                Directory.CreateDirectory(_cacheDir);
            }
            foreach (var item in Enum.GetValues(typeof(AssetType)))
            {
                if (!File.Exists(_cacheDir +@"\"+ item.ToString().ToLower()))
                {
                    Directory.CreateDirectory(_cacheDir +@"\"+item.ToString().ToLower());
                }
            }
        }

        _cacheDir = @"H:\EduCache";
        
    }

        

    

}
